package cn.zyjblogs.starter.redis.utils.lock;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * Copyright (C), 2021, 北京同创永益科技发展有限公司
 *
 * @author zhuyijun
 * @version 3.0.0
 * @description
 * @date 2022/5/23 11:01
 */
@Data
@AllArgsConstructor
@Builder
public class RedisLock {
    /**
     * 锁名称
     */
    private String lockKey;

    /**
     * 锁值
     */
    private String lockValue;

    /**
     * 过期时间
     */
    private Long expire;

    /**
     * 获取锁超时时间
     */
    private Long acquireTimeout;

    /**
     * 获取锁次数
     */
    private int acquireCount;

    /**
     * 锁实例
     */
    private Object lockInstance;

    /**
     * 锁执行器
     */
    private LockExecutor lockExecutor;

    /***
     * 解锁
     * @author zhuyijun
     * @Description
     * @date 15:10
     */
    public void unLock() {
        if (lockExecutor != null && lockInstance != null && !StringUtils.isEmpty(lockKey)) {
            lockExecutor.releaseLock(lockKey, lockValue, lockInstance);
        }
    }
}
